package useFn;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class demo3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        myCallable myCallable = new myCallable();
        myCallable myCallable2 = new myCallable();
        FutureTask<String> task = new FutureTask<>(myCallable);
        FutureTask<String> task2 = new FutureTask<>(myCallable2);
        Thread thread = new Thread(task,"线程名称1"); // 直接设置线程1 的名称
        Thread thread2 = new Thread(task2,"线程名称2"); // 直接线程2 的名称
        System.out.println(thread.getName());
        System.out.println(thread2.getName());
        thread.start();
        thread2.start();
        System.out.println(task.get());
        System.out.println(task2.get());
    }
}

class myCallable implements Callable<String> {
    @Override
    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName() + ":hh"); // 使用Thread.currentThread 就可以获取当前线程
        return "你好";
    }
}